package com.springcloud.consumer.controller;

import com.springcloud.consumer.aspect.WebLog;
import com.springcloud.consumer.feign.HelloFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class HelloController {

    @Qualifier("com.springcloud.consumer.feign.HelloFeign")
    @Autowired
    private HelloFeign helloFeign;

    @Autowired
    @Qualifier("singleresttemplate")
    private RestTemplate restTemplate;


    @GetMapping("/test")
    @WebLog(description = "test")
    private String test(HttpServletRequest request,String name){
        System.out.println(name);
        return name;
    }

    @GetMapping("/hello")
    @WebLog(description = "hello")
    public String hello(HttpServletRequest request,String name, Long time){
        if (time == null){
            time = 2L;
        }
        log.info("feigin start");
        String provoderResult = helloFeign.provider(name, time);
        log.info("feigin finish");
        return "consumer " + name + ":" + provoderResult;
    }
}
